package com.cloudweb.dingding;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiAttendanceListRequest;
import com.dingtalk.api.response.OapiAttendanceListResponse;
import com.redmoon.dingding.service.auth.AuthService;
import com.taobao.api.ApiException;
import java.util.Arrays;

public class AttendanceSyncUtil {
    /**
     * 获取考勤打卡记录
     *
     * @param args
     */
    public static void main(String args[]) {
        // 获取服务端接口调用凭证 access_token
        String access_token = AuthService.getAccessToken();

        try {
            // 通过调用接口获取考勤打卡结果
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/list");
            OapiAttendanceListRequest req = new OapiAttendanceListRequest();
            // 查询考勤打卡记录的起始工作日
            req.setWorkDateFrom("2024-01-06 08:00:00");
            // 查询考勤打卡记录的结束工作日
            req.setWorkDateTo("2024-01-08 23:00:00");
            // 员工在企业内的 userid 列表，最多不能超过 50 个。
            req.setUserIdList(Arrays.asList("434824203039709819,5254566961692673"));
            // 表示获取考勤数据的起始点
            req.setOffset(0L);//表示获取考勤数据的条数，最大不能超过 50 条。
            req.setLimit(10L);
            req.setIsI18n(false);
            OapiAttendanceListResponse rsp = client.execute(req, access_token);
            System.out.println(rsp.getBody());
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }
}